import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core';
import { CudTableService } from 'app/public/serve/cud-table/cud-table.service';
import { Service } from '../../../server/server';
import { template_attribute } from '../../product.data';
import { HintsService } from '../../../public/serve/hints/hints.service';
import { InitService } from '../../../public/serve/init/init.service';
import { DatePipe } from '@angular/common';
declare var $: any;
@Component({
  selector: 'app-template-attribute-edit',
  templateUrl: './template-attribute-edit.component.html',
  styleUrls: ['./template-attribute-edit.component.css']
})
export class TemplateAttributeEditComponent implements OnInit {

  @Output() onSubmit = new EventEmitter<void>();

  details: object = {};
  keywordListVal : Array<object>;
  @Input() themeTagListVal: any;

  constructor(
    private server: Service,
    public initService: InitService,
    private request: CudTableService,
    private hintsService: HintsService,
    private datePipe: DatePipe,
  ) { }

  ngOnInit() {}

  /**
   * 主题词详情
   * @param info
   */
  _details(info: object){
    this.details = info;
  }

  /**
   * 编辑保存
   */
  _onSubmit(info){
    info.token = template_attribute.retrieval.token;
    info.createBy = this.server.getuserName();
    
    this.request
    .postRequest(this.server.baseUrl + "Service/Config/updateMetaDataTemplateAttr",info)
    .then((res: any)=>{
     
      if(res.result_code === '0000'){
        this._editInit();
      }

      this.hintsService.messages(res.message,res.result_code);
      return;
    })
    .catch(err=>{
      this.hintsService.messages("error","error");
      this._editInit();
      return;
    });
  }

  /**
   * 初始化
   */
  private _editInit(){
    this.initService._init();
    $("#templateAttributeUpdate").modal("hide");
    this.onSubmit.emit();
  }

}
